<template>
	<view class="wrap">
		<view class="content">
				<view class="title">请输入您的兑换码</view>
				<input class="u-border-bottom" type="text" v-model="voucher_code" placeholder="请输入会员卡号/会员兑换码" />
				<br>
				<button @tap="submitVoucherCode" :style="[inputVoucherCode]" class="getCaptcha">确认兑换</button>
		</view>
		<wx-share :title='shop.name' :desc="shop.store_introduction" :imgUrl="shop.cover" :link="currentPage" ref="wxs">
		</wx-share>
		<custom-tabbar></custom-tabbar>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				currentPage: location.href,
				scrollTop: 0,
				shop: {},
				user: {},
				voucher_code:''
			}
		},
		computed: {
			inputVoucherCode() {
				let style = {};
				if (this.voucher_code) {
					style.color = "#fff";
					style.backgroundColor = this.$u.color['warning'];
				}
				return style;
			}
		},
		onLoad() {
			this.getShop();
		},
		mounted() {
			this.getUserInfo()
		},
		methods: {
			getShop() {
				this.$u.post('/shopping/shop-setting', {}).then(res => {
					this.shop = res;
				}).catch(e => {
			
				})
			},
			getUserInfo() {
				this.$u.post('/user/info', {}).then(res => {
					console.log(res)
					this.user = res;
					if (this.user.verified!=='yes') {
						uni.showToast({
							title: '请先完成车主注册'
						})
						this.openPage('/pages/ucp/profile')
					}
				}).catch(e => {
					console.log(e)
				})
			},
			openPage(jumpURL, params = {}) {
				this.$u.route({
					type: 'to',
					params: params,
					url: jumpURL,
					animationType: 'slide-in-bottom'
				});
			},
			submitVoucherCode(){
				this.$u.post('/user/upgrade-membership-by-voucher-code', {voucher_code:this.voucher_code}).then(res => {
					console.log(res)
					uni.showToast({
						title: '兑换成功'
					})
					uni.navigateBack({
					
					})
				}).catch(e => {
					console.log(e)
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.wrap {
		font-size: 28rpx;

		.content {
			width: 600rpx;
			margin: 80rpx auto 0;

			.title {
				text-align: left;
				font-size: 50rpx;
				font-weight: 500;
				margin-bottom: 100rpx;
				text-align: center;
			}

			input {
				text-align: left;
				margin-bottom: 10rpx;
				padding-bottom: 6rpx;
			}

			.tips {
				color: $u-type-info;
				margin-bottom: 60rpx;
				margin-top: 8rpx;
			}

			.getCaptcha {
				background-color: rgb(253, 243, 208);
				color: $u-tips-color;
				border: none;
				font-size: 30rpx;
				padding: 12rpx 0;

				&::after {
					border: none;
				}
				&:active{
					opacity: .8;
					transition: 300ms;
				}
			}

			.alternative {
				color: $u-tips-color;
				display: flex;
				justify-content: space-between;
				margin-top: 30rpx;
			}
		}

		.buttom {
			.loginType {
				display: flex;
				padding: 350rpx 150rpx 150rpx 150rpx;
				justify-content: space-between;

				.item {
					display: flex;
					flex-direction: column;
					align-items: center;
					color: $u-content-color;
					font-size: 28rpx;
				}
			}

			.hint {
				padding: 20rpx 40rpx;
				font-size: 20rpx;
				color: $u-tips-color;

				.link {
					color: $u-type-warning;
				}
			}
		}

		.payment-info {
			background-color: #FFF;
			padding: 0 30rpx 30rpx 30rpx;
			border-radius: 10rpx;
			box-sizing: border-box;
			margin-bottom: 30rpx;

			.bold {
				font-weight: bold;
				border-bottom: 1rpx solid #c9c8d2;
			}

			.calculation-data {
				display: flex;
				flex-direction: row;
				justify-content: space-between;
				padding-top: 30rpx;
				// margin-bottom: 10rpx;

				.data-title {
					width: 6em;
					font-weight: bold;
				}

				.data-text {
					flex: 1
				}
			}

		}
	}
</style>
